package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.ActivityBean;
import com.magic.gre.entity.base.BaseListModel;
import com.magic.gre.entity.base.BaseObjectModel;
import com.magic.gre.mvp.contract.MyActivityContract;
import com.magic.gre.mvp.model.MyActivityModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;

/**
 * Author: Lmoumou
 * Date: 2019-01-10 20:16
 * 文件名: MyActivityPresenterImpl
 * 描述:
 */
public class MyActivityPresenterImpl extends BasePresenterImpl<MyActivityContract.View, MyActivityContract.Model>
        implements MyActivityContract.Presenter {
    public MyActivityPresenterImpl(MyActivityContract.View view) {
        super(view);
    }

    @Override
    protected MyActivityContract.Model creatModel() {
        return new MyActivityModelImpl();
    }

    @Override
    public void pActivityList(int pageNo) {
        mModel.mActivityList(new CommonObserver<BaseListModel<ActivityBean>>(new TypeToken<BaseListModel<ActivityBean>>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseListModel<ActivityBean> activityBeanBaseListModel) {
                mView.vActivitylist(activityBeanBaseListModel.body);
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, pageNo);
    }

    @Override
    public void pActDetails(final String activityId,String device) {

        mModel.mActDetails(new CommonObserver<BaseObjectModel<ActivityBean>>(new TypeToken<BaseObjectModel<ActivityBean>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<ActivityBean> activityBeanBaseObjectModel) {
                mView.vActDetails(activityBeanBaseObjectModel.body,activityId);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, activityId,device);
    }
}
